package com.example.floatingactionbutton;

import androidx.appcompat.app.AppCompatActivity;

import android.content.res.ColorStateList;
import android.graphics.Color;
import android.os.Build;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.TextView;

import com.google.android.material.floatingactionbutton.FloatingActionButton;
import com.google.android.material.snackbar.Snackbar;

/***
 * 包含3部分
 * 1.基本使用以及动态的修改属性
 * 2.与snackbar和CoordinatorLayout联动
 * 3.与rv联动，rv上下滑动的同时隐藏与显示fab
 * 4.注意：上面两种联动效果放到CoordinatorLayout中！~~
 * 5.一些三方库可以写在这里
 */
public class MainActivity extends AppCompatActivity {

    private FloatingActionButton mFab;
    private TextView mTv;
    private FloatingActionButton mFab1;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        initView();

        //设置尺寸大小
        mFab.setSize(FloatingActionButton.SIZE_NORMAL);
//        mFab.setCustomSize(20);
        //设置图片资源
        mFab.setImageResource(R.mipmap.ic_launcher_round);
        //设置背景颜色
        mFab.setBackgroundTintList(ColorStateList.valueOf(Color.RED));
        //设置阴影的高度
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
            mFab.setElevation(20);
        }
        mFab.setCompatElevation(20);
        //设置尺寸的大小
        mFab.setCustomSize(100);
        mFab.setExpanded(true);
        //设置点击效果
        mFab.setRippleColor(Color.TRANSPARENT);

        mFab.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                //这里弹出来的Snackbar，可以右滑取消显示
                //Snackbar.make(mCoordinator, "我是SnackBar", Snackbar.LENGTH_LONG).show();
                //这里使用mTv、mCoordinator、v都是可以的，证明这要在CoordinatorLayout中就可以
                Snackbar.make(mTv, "我是SnackBar", Snackbar.LENGTH_LONG)
                        .addCallback(new Snackbar.Callback() {
                            @Override
                            public void onDismissed(Snackbar transientBottomBar, int event) {
                                super.onDismissed(transientBottomBar, event);
                                switch (event) {
                                    case Snackbar.Callback.DISMISS_EVENT_CONSECUTIVE:
                                        Log.i("zxd", "DISMISS_EVENT_CONSECUTIVE");
                                        break;
                                    case Snackbar.Callback.DISMISS_EVENT_MANUAL:
                                        Log.i("zxd", "DISMISS_EVENT_MANUAL");
                                        break;
                                    case Snackbar.Callback.DISMISS_EVENT_SWIPE:
                                        if (!mTv.getText().toString().contains("?能"))
                                            mTv.append("能");
                                        Log.i("zxd", "滑动");
                                        break;
                                    case Snackbar.Callback.DISMISS_EVENT_TIMEOUT:
                                        Log.i("zxd", "删除成功");
                                        break;
                                    case Snackbar.Callback.DISMISS_EVENT_ACTION:
                                        Log.i("zxd", "撤销了删除操作");
                                        break;
                                }
                            }
                        })
                        .show();
            }
        });
    }

    private void initView() {
        mTv = findViewById(R.id.tv1);
        mFab = findViewById(R.id.fab);
        mFab1 = findViewById(R.id.fab1);
    }
}
